package com.efast.cafe.portal.controller;


import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.cafe.framework.bean.ResultBean;
import com.efast.cafe.framework.enums.ResultStatus;
import com.efast.cafe.framework.vo.TreeVo;
import com.efast.cafe.portal.service.common.IResourceService;
import com.efast.cafe.util.ConfigUtil;


import net.sf.json.JSONArray;
import net.sf.json.JSONObject;



@Controller
public class HomeController {
	@Autowired
	private IResourceService portalResourceService;
	
	
	@RequestMapping("/frame_center/portal/menus")
	public @ResponseBody List<TreeVo> initMenuTree(HttpServletRequest request, HttpServletResponse response,
			@RequestParam(required = false) Long moduleInfoId,
			@RequestParam String i18n){
		return portalResourceService.queryCurrentUserMenusTree(i18n);
	}
	
	@RequestMapping("/frame_center/portal/getModuleList")
	public @ResponseBody ResultBean getModuleConfig(){
		ResultBean res = new ResultBean(true, "");
		try{
			res.setObject(ConfigUtil.getSystemModules());
		}catch(Exception e){
			res.setSuccess(false);
			res.setErrorCode(ResultStatus.SYS_ERROR.getCode());
		}
		return res;
	}
	/**
	 * 首页 消息栏服务， 查询未读消息的数量，列表中显示最近5条 未读数不足5条用最近已读消息补足
	 * 最多暂时5条 可点击查看全部 进行查询其他未读和已读
	 * @return
	 */
	@RequestMapping("/home/my_message")
	public @ResponseBody ResultBean queryMyMessage(){
		ResultBean res = new ResultBean(true, "");
//		{
//			"unread" : 3, //未读数量
//			"data" : [
//			          {
//			        	  "msg":"您收到了某某的点赞",
//			        	  "date" : "2018-4-12 10:35:35",
//			        	  "isUnread":0
//			           } 
//			         ]
//			
//		}
		JSONObject jo = new JSONObject();
		jo.put("unread", 3);
		JSONArray jr = new JSONArray();
		JSONObject jo1 = new JSONObject();
		jo1.put("msg", "您收到了冯宣銘的点赞。");
		jo1.put("date", "2018-4-12 10:35:35");
		jo1.put("isUnread", 0);
		JSONObject jo2 = new JSONObject();
		jo2.put("msg", "您的工作周报有新的评论。");
		jo2.put("date", "2018-4-12 10:35:35");
		jo2.put("isUnread", 0);
		JSONObject jo3 = new JSONObject();
		jo3.put("msg", "您发表的“JAVA开发规范”有新的评论。");
		jo3.put("date", "2018-4-12 10:35:35");
		jo3.put("isUnread", 0);
		JSONObject jo4 = new JSONObject();
		jo4.put("msg", "您收到了冯宣銘的点赞。");
		jo4.put("date", "2018-4-12 10:35:35");
		jo4.put("isUnread", 1);
		JSONObject jo5 = new JSONObject();
		jo5.put("msg", "您收到了冯宣銘的点赞。");
		jo5.put("date", "2018-4-12 10:35:35");
		jo5.put("isUnread", 1);
		jr.add(jo1);
		jr.add(jo2);
		jr.add(jo3);
		jr.add(jo4);
		jr.add(jo5);
		jo.put("data", jr);
		res.setObject(jo);
		return res;
	}
	
	/**
	 * 通知
	 * @return
	 */
	@RequestMapping("/home/my_notice")
	public @ResponseBody ResultBean queryMyNotice(){
		ResultBean res = new ResultBean(true, "");
//		{
//			"unread" : 3, //未读数量
//			"data" : [
//			          {
//			        	  "msg":"您收到了某某的点赞",
//			        	  "date" : "2018-4-12 10:35:35",
//			        	  "isUnread":0
//			           } 
//			         ]
//			
//		}
		JSONObject jo = new JSONObject();
		jo.put("unread", 3);
		JSONArray jr = new JSONArray();
		JSONObject jo1 = new JSONObject();
		jo1.put("msg", "您的请假审批已通过");
		jo1.put("date", "2018-4-12 10:35:35");
		jo1.put("isUnread", 0);
		JSONObject jo2 = new JSONObject();
		jo2.put("msg", "您所在的组织架构发生变化.");
		jo2.put("date", "2018-4-12 10:35:35");
		jo2.put("isUnread", 0);
		JSONObject jo3 = new JSONObject();
		jo3.put("msg", "您的角色发生变化.");
		jo3.put("date", "2018-4-12 10:35:35");
		jo3.put("isUnread", 0);
		JSONObject jo4 = new JSONObject();
		jo4.put("msg", "您的\"eMFG\"项目有新的任务。");
		jo4.put("date", "2018-4-12 10:35:35");
		jo4.put("isUnread", 1);
		JSONObject jo5 = new JSONObject();
		jo5.put("msg", "您有2份周报还未提交成功。");
		jo5.put("date", "2018-4-12 10:35:35");
		jo5.put("isUnread", 1);
		jr.add(jo1);
		jr.add(jo2);
		jr.add(jo3);
		jr.add(jo4);
		jr.add(jo5);
		jo.put("data", jr);
		res.setObject(jo);
		return res;
	} 
	@RequestMapping("/home/my_task")
	public @ResponseBody ResultBean queryMyTask(){
		ResultBean res = new ResultBean(true, "");
		return res;
	}
	
}
